The present invention relates in general to virtual memory systems and in particular to systems and methods for on-demand memory management.
Computer systems generally include various peripheral devices, such as graphics processing cards, mass storage (e.g., disk or tape) drives, printers, and so on, with which the central processing unit interacts. A device driver program that executes on the CPU is typically provided for each peripheral device; operating system and/or application programs executing on the CPU invoke functions of the driver program to interact with the peripheral device.
Many of these interactions involve accessing memory (or other addressable storage) located on the a peripheral device. For example, many computer systems include a graphics card as one peripheral device. The graphics card controls the system's display device. Typically, the graphics card includes a memory area (called a frame buffer) that stores data for individual pixels of a display device, and images are displayed by scanning out the pixel data from the frame buffer. The CPU may execute an application program that generates pixel data to be displayed and write this data directly to the frame buffer on the graphics card. As another example, commands to be executed by a graphics co-processor located on the graphics card are may be queued for execution in memory on the graphics card; the CPU can control the graphics co-processor by writing commands to this queue. Numerous other examples pertaining to graphics cards and other peripheral devices are well known.
To enable the CPU to directly access peripheral device memory, the peripheral device memory is typically mapped to a virtual memory space of the CPU. For instance, in some versions of the Microsoft Windows operating system, a 32-bit virtual address space (corresponding to 4 GB of virtual memory) is defined, and peripheral device memory is mapped to a set of virtual addresses at system startup. Mapping associates each virtual address with a specific memory location in the peripheral device, so that the CPU is able to process commands referencing a virtual address by accessing the associated location in the peripheral device memory. When peripheral device memory is not mapped to virtual memory, accessing the device memory generally requires an indirect path, in which a memory access command is transmitted to the peripheral device, which executes the command and returns an appropriate result.
In the past, virtual memory seemed inexhaustible, but for modern systems and programs, virtual memory—which is typically mapped to application and operating system program code and data on disk as well as to system memory and peripheral devices—is becoming a limited resource as the sizes of program code, system memory, and peripheral device memory are all increasing. As just one example, currently available graphics cards have as much as 256 MB of memory, and cards with 512 MB or more are on the horizon. Mapping each byte of graphics memory to a byte of virtual memory consumes a large fraction of the virtual memory, leaving less of the space available for other mappings. Depending on system configuration (e.g., size of the virtual memory space) and other parameters (e.g., virtual memory requirements of various other programs or devices and system-dependent restrictions on virtual memory use), running out of virtual memory has become a distinct possibility. Moreover, even if some virtual memory remains available, reducing the amount of free virtual memory beyond a certain point can adversely affect performance of the system.
Leaving the peripheral device memory unmapped is sometimes impractical. As noted above, direct access to the peripheral memory by the CPU requires a virtual memory mapping. While indirect access is possible without a mapping (e.g., by passing memory requests to a peripheral co-processor), indirect access paths are generally slower and may increase the load on the CPU and/or peripheral co-processors. Where frequent or fast access to peripheral device memory is required, as is usually the case with graphics cards, reliance on indirect access paths can impair system performance.
Therefore, a mechanism for enabling direct CPU access to peripheral device memory that reduces virtual memory consumption would be desirable.